home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NOVA - For the NeXT Workstation
/
NOVA - For the NeXT Workstation.iso
/
Newsletters
/
GEnieUnixNews
/
unxnl-04.90
< prev
next >
Wrap
Text File
|
1992-12-27
|
14KB
|
312 lines
_ __ _ _ __ _ __
// / //| // || \\| N E W S
//_/ // |// || |\\ Vol 1, Issue 5 - April 1990
R o u n d T a b l e
Items of interest to participants of the GEnie Unix RoundTable
The RoundTable SysOps are:
Dave Weinstein......OLORIN Brian Riley.........DELPHI
Gary Smith..........GARS Chris North-Keys....HARP
Rick Mobley.........LRARK All Unix SysOps.....UNIXSYSOPS$
We strongly encourage you to contact any or all of us if you have -ANY-
comments or suggestions. This is -YOUR- RoundTable. We are here to make
your participation as pleasant and beneficial as possible.
ED: editor notes (modularity)
--
If someone should ask you,"Why is *nix in all those little chunks of code
instead of one nice, big monolithic program ?", tell them it is because the
creators of Unix wanted their 'child' to emulate life, not Sherman tanks. I
don't know if that is really a underlying reason, but it certainly seems so.
When I take a drink of water I usually take a modular approach. ie: take
glass, open tap, place glass under tap, fill glass, turn off tap, raise glass
to lips, drink. Now,I have drunk straight from a garden hose, and let me tell
you that approach is messy. It accomplishes the same purpose, but it leaves a
lot to be desired in the way of style.
So it also is in Unix. Small modular pieces molded to create a homogenous
product, each seperate, seemingly miniscule task combining to accomplish large
tasks. The analogy of a jigsaw puzzle can be made; with one piece not having
any special significance, yet the puzzle is lacking without it.
This month's newsletter is also the result of several independent contri-
butions. It seems particularly appropriate that so many pieces came from many
different sources, since it resulted in our first (almost) theme or concept
newsletter. The common thread running throughout most of this month's digest
is scripts, starting with Mike Nolan's column.
We hope you enjoy. Gars
BEGINNERS PERSPECTIVE: Mike Nolan looks at scripts in his second installment.
---------------------
Uncorking unix
by Mike Nolan
"Getting Started in Shell Programming"
Unix is by far the most powerful operating system I've ever worked with.
However, there are always things it doesn't do that I need, either to help
with a particular problem or because I am used to having it on other systems.
It is often possible to add these capabilities by writing a 'shell script'.
To do this, it is helpful to have some idea what a shell is and how it works.
What follows is *my* explanation of the unix shell, which differs some from
other definitions I have read. These other definitions may be more
technically accurate than mine, as I am trying to simplify as much as possible.
The unix operating system may be described as consisting of a large number of
programs collectively referred to as the 'kernel'. These are programs which
the average user doesn't see or interact with very much. In between the kernel
and the user is another program which responds to user requests. This program
is the shell.
Actually, there are at least three shells used on unix systems. Virtually
every unix system has the "Bourne shell", most have the "C shell", and an
increasing number have the more recent "Korn shell". (I only have the
Bourne and the C shell on my system.)
These shells have many things in common. All of them respond to user requests
in three ways:
1. By performing the task directly.
2. By passing the task on to the kernel, in one or more steps.
3. By starting up one or more additional programs to perform the task.
Most requests involve more than one of these responses.
When the shell starts up another program, this program usually runs
independently of the shell program and is referred to as a 'subshell'.
It is even possible that the subshell will be a *copy* of the original shell!
A 'shell script' is nothing more than a file which contains one or more
requests to be passed on to a shell. Shell scripts range from simple one-
liners which are in a script file just to avoid retyping frequently
used commands to complex groups of commands in which the later commands are
chosen based on the results of earlier commands. Shell scripts are, in fact,
a type of programming language.
Shell scripts may be written specifically for each of the shells, but are
most commonly written for the Bourne shell, especially if the shell script is
to be passed on to other users, as *EVERYBODY* has the Bourne shell. The Korn
shell was designed to include *all* of the capabilities of the Bourne shell
and add more capabilities; many feel it will eventually replace the Bourne
shell completely.
The C shell is substantially different from the Bourne shell, but will start
up a Bourne shell to run a shell script if the first character of the script
is *ANYTHING* other than a pound sign (#). Many scripts have a colon (:) as
the only thing on the first line just to make sure that they are running on a
Bourne shell instead of a C shell. A colon is a 'null' command in the Bourne
shell, meaning it does nothing, so it won't mess up the Bourne shell.
As an example of a simple script which saves me from retyping a frequently
used command, I offer the following script, which I call 'count'
ls -l $1 | cut -c25-31|awk '{s += $1} END {print s " bytes"}' -
This script gives a total count on the number of bytes in a directory, or
in a group of files in the directory. This script makes use of two very
important ingredients:
1. Pipes or pipelining of input and output from one program to another.
2. Information passed to the script by the user at the time the script is
started, by including it on the command line. This information can vary
from one time the script is executed to another.
Pipelining is best described by giving a visual example of the script 'count':
__ __ __ __
\______/ \______/
ls ______ cut ______ awk
__/ \__ __/ \__
The first command ,'ls', lists the directory (or possibly only some of the
files in the directory.) This information is passed along as the input to the
second program, 'cut', which eliminates all information other than columns 25
through 31 (which contains the size of each file listed by ls), and then passes
this information as the input to the third program, 'awk'. Awk is a program
which, among other things, can do arithmetic on the input provided it, and in
this case it adds up a string of numbers (file sizes) and gives the
total as its output, which is then displayed on the screen.
When the 'count' script is executed, the shell starts up the 'ls' command,
passes the output it generates on to the 'cut' command, and then passes
that output along to 'awk'. In fact, ls, cut, and awk are all running
at the same time, in three separate subshells, with cut patiently waiting
for ls to pass it output, processing it, and then passing it along to awk,
which also sits patiently waiting. [A *fourth* shell is also created. It is
another copy of the Bourne shell, and actually process the script file.]
Pipelining is related to a more complicated process called redirection, which
will be the subject of a future column.
The other tool demonstrated in the 'count' script is the passing of information
from the command line to the script. The shell interprets *all* input to it
as consisting of a command, followed by a series of parameters, generally
separated by a space or tab.
The '$1' in the ls command refers to the first parameter *after* the command
itself. If you type in
count *xyz
then 'count' will only consider files that end in 'xyz'. Parameters passing
is more complicated than it appears, and will be dealt with more completely
next month.
Next month I'll also talk about how a shell script can keep track of
information within it and pass this information on to subshells.
Sub: New Unix RT SysOp
----------------------
Yes, there has been another changing of the guard. Christopher Cilley was not
able to keep his other commitments and still contribute to the maintenance of
the GEnie Unix RoundTable as much as desired. We wish Christopher well and
thank him for his efforts on our behalf.
Stepping in to replace Christopher is Brian Riley. Many of you already know
Brian from his contributions the the GEnie Unix RoundTable as a user. It is a
priviledge to welcome Brian as the newest member of your Unix support team on
GEnie. Brian's Username: DELPHI
WHO : Meet Brian Riley
---
Brian is a 28 year old computer technician currently working in
the Philadelphia area. He learned UNIX on an AT&T 3B2/300 running
UNIX SVR 2.02, in 1985. Since then he have worked with SVR 2.02 -
3.1.1, CTIX (Convergent Technologies UNIX) 5.0 - 5.3, and 3B1 UNIX
3.0 - 3.51m. Brian currently owns a 3B1 and an AT&T PC6300 (with
enhancements) and 3 other computers. He programs in C (UNIX & DOS),
and is learning Pascal and Assembler. He also enjoy Fantasy and Science
Fiction books and Advanced Dungeons & Dragons. :)
CONTEST WINNER :
--------------
From: OLORIN David H. Weinstein
To: M.NOLAN Michael E. Nolan
Sub: Unix RT Upload Contest
Congratulations! As the winner of the February-March Unix RT Upload
Contest, you are entitled to one day of your choice free of charge
in the Unix RoundTable (and the Unix RoundTable alone). For us
to award you your prize, we will need your GEnie User Number and the
day you wish to receive free of charge.
--Dave Weinstein
If you wish to be the recipient of this letter and enjoy some free access
time on GEnie, all you have to do is start sharing your public domain
files. Non-prime time uploads are free time themselves - so share !
delete alias unerase set from Dave Weinstein (OLORIN)
------
Most microcomputer users are familiar with the "unerase" family of
utilities. But the tricks which make it possible to restore an erased
file from a single-tasking system do not work on multi-user, multi-tasking
operating systems. The following are a few C-Shell aliases I use to keep
from accidentally erasing too much of my work.
alias erase "/bin/rm"
alias rm "mv \!* ~/.rm"
alias dead "ls ~/.rm"
alias restore "mv ~/.rm/\!* ./"
alias purge "/bin/rm -rf ~/.rm; (cd ; mkdir .rm)"
Usage of these aliases is fairly straightforward. Be sure to have created
the directory ~/.rm before using them.
FAST and NASTY, DOWN and DIRTY: quick fix scripts that do something
--------------------------------
This script first appeared in UnixWorld Vol. V, No. 8. It displays users
from the /usr/passwd file, and has filters to only show what you want.
#----cut here----
:
# users List all valid system users
# Author: Wendell Holmes, 1987
#
sed s/:.*//g /etc/passwd |
while read user
do
if [ -n "$user" ]
then
case $user in
root ) ;;
sysadm ) ;;
bin ) ;;
asg ) ;;
sysinfo) ;;
network) ;;
lp ) ;;
dos ) ;;
news ) ;;
cron ) ;;
uucp ) ;;
nuucp ) ;;
* ) echo $user ;;
esac
fi
done
TODAY IS ?.... In honor of our script theme, here's a second handy one.
-------- This one from Rick Mobley (LRARK) makes quick work out of
determining the current day when glancing at the calendar.
Thought you could use a neat script for the Newsletter. Here is one that
uses terminfo instead of termcap and highlights the current day of the week.
I don't remember where or when I got it, but it comes in very handy.
Rick
#----cut here----
:
# @(#) today Display calendar highlighting today
# Author: Mathieu Federspiel
#
# Get date in the form produced by cal,
# that is, removing any leading zero:
day=`date '+%d' | sed 's/0\([123456789]\)/ \1/'`
month=`date +%m`
year=`date +%y`
#
# Store start and end stand out terminal codes,
# translating any possible "&" to "=":
smso=`tput smso | tr "&" "="`
rmso=`tput rmso | tr "&" "="`
#
# Get calendar, add space to line, insert codes,
# and translate "=" back to "&":
cal $month $year | sed "s/^/ /" |
sed "3,\$s/ ${day}/ ${smso}${day}${rmso}/" |
tr "=" "&"
--------
REMINDER - This newsletter is being sent to you 'by request'. If you do
not wish to keep receiving it, e-mail a stop notice to GARS. On the other
hand, we would very much appreciate it if you would pass the word that we
do distribute this item near the tenth (10th) of each month to anyone on
GEnie who requests it, and will gladly add any name that is requested via
the same route... e-mail to GARS.
P L E A S E also remember contributions are most welcome. Please e-mail
items and/or suggestions to GARS.
(EOF)
Trademark and Copyright notices:
Unix is a Trademark of AT&T, GEnie, LiveWire, and RoundTable are Trademarks
of General Electric Information Services Company, Xenix is a Trademark of
Microsoft Corporation, UnixWorld is a Trademark of McGraw-Hill.
The contents of this newsletter are copyright (c) 1990 and may be copied whole
or in part only if original credit is included. The GEnie UNIX RoundTable is
not affiliated with AT&T.
ay be copied whole
or in part only if original credit is included. The GEnie UNIX RoundTable is
not